package com.example.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {
    private Long current;
    private List<T> data;
    private int errorCode;
    private String message;
    private Long pages;
    private Long size;
    private boolean success;
    private Long total;

    public static <T> PageResult<T> success(IPage<T> page) {
        PageResult<T> result = new PageResult<>();
        result.setData(page.getRecords());
        result.setCurrent(page.getCurrent());
        result.setSize(page.getSize());
        result.setTotal(page.getTotal());
        result.setSuccess(true);
        return result;
    }

    public static <T> PageResult<T> error(String message) {
        PageResult<T> result = new PageResult<>();
        result.setMessage(message);
        result.setSuccess(false);
        return result;
    }

}
